#include<stdio.h>
struct Stu 
{
	char name[20];
	int age;
};
void swap(char* buf1, char* buf2, int size)
{
	int i = 0;
	char temp = 0;
	for (i = 0; i < size; i++)
	{
		temp = *buf1;
		*buf1 = *buf2;
		*buf2 = temp;
		buf1++;
		buf2++;
	}
}
int comper_age(const void* p1, const void* p2)
{
	return ((struct Stu*)p1)->age - ((struct Stu*)p2)->age;
}
void bubble_sort(void* base, int se, int size, int (*cmp)(const void*, const void*))
{
	int i = 0;
	for (i = 0; i < se - 1; i++)
	{
		int j = 0;
		for (j = 0; j < se - 1 - i; j++)
		{
			if (cmp((char*)base + j * size, (char*)base + (j + 1) * size)>0)
			{
				swap((char*)base+j*size,(char*)base+(j+1)*size,size);
			}

		}
	}
}

void test()
{
	struct Stu arr[] = { {"zhangsan",75},{"lisi",20},{"wangwu",35}};
	int se = sizeof(arr)/sizeof(arr[0]);
	bubble_sort(arr, se, sizeof(arr[0]), comper_age);
}
int main()
{
	test();
	
	return 0;
}